<script>
import DefaultMoreEntity from './container/DefaultMoreEntity.vue'
import { getToken } from '@/utils/auth'
import { requestGet } from '@/api/system/common'
import DefaultEntity from '@/template/entityTemp/defaultEntity.vue'
export default {
  name: 'More',
  components: { DefaultEntity, DefaultMoreEntity },
  data() {
    return {
      type: 'default'
    }
  },
  computed: {
    theme() {
      return this.$store.getters.theme
    }
  },
  watch: {
    theme: {
      handler(newVal, oldVal) {
        const app = document.querySelector('body')
        if (undefined !== newVal) {
          app.classList.add('theme-' + newVal + '-content')
        }
        if (undefined !== oldVal) {
          app.classList.remove('theme-' + oldVal + '-content')
        }
      },
      deep: true
    }
  },
  created() {
    const app = document.querySelector('body')
    const theme = this.$store.getters.theme === undefined ? 'default' : this.$store.getters.theme
    console.log('主题', this.$store.getters.theme)
    app.classList.add('theme-' + theme + '-content')
    this.initTemp()
  },
  methods: {
    initTemp() {
      let url = 'rest/api/guest/temp/v2/column/analysis/obj'
      if (getToken()) {
        url = 'rest/api/temp/v2/column/analysis/obj'
      }
      const mid = this.$route.query.temp
      if (undefined !== mid && mid !== null && mid !== '') {
        requestGet(url, { cid: mid })
          .then(res => {
            const { data } = res
            this.$bus.emit('moreTemp', data)
          }).catch(() => {
            this.$bus.emit('moreTemp', null)
          })
      }
    }
  }
}
</script>

<template>
  <div>
    <default-more-entity v-if="type==='default'" />
    <default-entity />
  </div>
</template>
